<!--
 @description 品类子级
 @fileName CateChild.vue
 @author zengqiongying
 @created 2023/03/15 15:12:01
-->
<template>
  <div class="custom-page">
    <MineHeader arrow :title="pageName" />
    <div class="page-content">
      <!-- <List
        ref="list"
        :finished.sync="finished"
        :reset-fun="resetData"
        :load="load"
        :refresh="load"
      > -->
      <div class="show-content-list">
        <ShowItem
          v-for="(item,i) in list"
          :key="i"
          :src="item.picUrl"
          :name="item.name"
          :host="imgHost"
          :column="4"
          is-cate
          @click="handleClickItem(item)"
        />
      </div>
      <!-- </List> -->
    </div>
  </div>
</template>

<script>
import MineHeader from '@/components/MineHeader'
import ShowItem from './ShowItem'
// import List from '@/components/PageList'
export default {
  name: 'GoodsCategoryChild',
  components: { MineHeader, ShowItem },
  filters: {},
  mixins: [],
  data() {
    return {
      pageName: '',
      parentId: this.$route.params.parentId, // 父类ID
      list: [],
      imgHost: process.env.VUE_APP_STATIC
    }
  },

  computed: {},

  created() {
    this.getChildList()
  },
  mounted() {},
  activated() {
    this.getChildList()
  },
  beforeRouteLeave(to, from, next) {
    const names = ['GoodsCategory', 'GoodsIndex']
    if (names.includes(to.name)) {
      sessionStorage.removeItem('cateChild')
      this.$removeKeepAliveCache(this)
    }
    next()
  },
  methods: {
    getChildList() {
      if (sessionStorage.getItem('cateChild')) {
        const obj = JSON.parse(sessionStorage.getItem('cateChild'))
        // console.log('子级品类', obj)
        if (obj && obj.id) {
          this.pageName = obj.name
          this.list = obj.children || []
        }
      }
    },
    resetPageData() {
      if (this.$refs.list) {
        this.$refs.list.resetPageData()
      }
    },
    resetData() {
      this.list = []
    },
    load(page, rows) {
      /* const data = {
        page,
        rows,
        spaceConfId: this.confId
      }
      return getCategoryPageBySpaceId(data).then(res => {
        const records = res.data.records || []
        this.list.push(...records)
        if (this.list.length >= res.data.total) {
          this.finished = true
        }
      }) */
    },
    handleClickItem(row) {
      const { categoryId, name } = row
      this.$router.push({ path: '/goods/list', query: { categoryId, name }})
    }
  }
}

</script>
<style lang='less' scoped>
.custom-page{
  padding-top:44PX;
}
.show-content-list{
  padding-top:20px;
  display: flex;
  flex-wrap: wrap;
}
</style>
